/*    file: SdlPresenter.h
 *    desc:
 *   
 * created: 2014-04-24 11:16:08
 *  author: zhengchuanjiang
 * company: 
 */ 


#if !defined SDLPRESENTER_H_
#define SDLPRESENTER_H_

#include <SDL.h>
#include "Ffmpeg.h"

#include "SharedPtr.h"

typedef std::shared_ptr< SDL_Texture >      SDL_TexturePtr;
////////////////////////////////////////////////////////////////////////////
namespace sdl
{

class Presenter
{
public:
    Presenter();
    ~Presenter();

    void reset();

    bool draw(SDL_Renderer* renderer, AVFrame* pFrame, int ratioX, int ratioY);

    bool draw(SDL_Renderer* renderer, AVFrame* pFrame);

    bool drawCache(SDL_Renderer* renderer, int ratioX, int ratioY);

protected:
    void resetTexture(SDL_Renderer* renderer, int width, int height);

    bool updateTexture(SDL_Renderer* renderer, AVFrame* pFrame);

    SDL_Rect getScaleRect(int srcWidth, int srcHeight, 
        int destWidth, int destHeight,
        int ratioX, int ratioY);

    SDL_Rect getScaleRect(const SDL_Rect& rc, int ratioX, int ratioY);

protected:
    SDL_TexturePtr  m_texture;
    SDL_Renderer*   m_renderer;

};


}
////////////////////////////////////////////////////////////////////////////
#endif //SDLPRESENTER_H_

